package com.binsoft.ndtta;

import java.util.ArrayList;

import com.binsoft.ndtta.R;

import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class TeamListFragment extends ListFragment
{
	private final String NO_TEAM = "<No Team>";
	
	private ArrayList<String> getTeamNames( Team[] teams )
	{
		ArrayList<String> names = new ArrayList<String>();
		
		for ( Team team : teams )
		{
			if ( team.name().isEmpty() )
			{
				names.add(  NO_TEAM );
			}
			else
			{
				names.add( team.name() );
			}
		}
		
		return names;
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState)
	{
		TeamListAdapter div1 = new TeamListAdapter( getActivity(), getTeamNames( Constants.div1), 0);
		TeamListAdapter div2 = new TeamListAdapter( getActivity(), getTeamNames( Constants.div2), 1);
		TeamListAdapter div3 = new TeamListAdapter( getActivity(), getTeamNames( Constants.div3), 2);
		
		SeparatedListAdapter adapter = new SeparatedListAdapter(getActivity());
		
		adapter.addSection(getResources().getString(R.string.DIVISION_1_DIVIDER), div1);
		adapter.addSection(getResources().getString(R.string.DIVISION_2_DIVIDER), div2);
		adapter.addSection(getResources().getString(R.string.DIVISION_3_DIVIDER), div3);
		
		setListAdapter(adapter);
		
		return super.onCreateView(inflater, container, savedInstanceState);
	}
}
